package com.smec.moblie.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.smec.moblie.R;
import com.smec.moblie.activity.RemesNoticeDetailActivity;
import com.smec.moblie.bean.MaintenanceNoticeBean;
import com.smec.moblie.view.RippleView;

import java.util.ArrayList;

/**
 * Created by sunyubo on 16/2/26.
 */
public class RemesNoticeAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private ArrayList<MaintenanceNoticeBean> maintenanceNoticeBeanList;
    private Context context;

    public RemesNoticeAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
        maintenanceNoticeBeanList = new ArrayList<MaintenanceNoticeBean>();
    }

    public void setList(ArrayList<MaintenanceNoticeBean> maintenanceNoticeBeanList) {
        this.maintenanceNoticeBeanList = maintenanceNoticeBeanList;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return maintenanceNoticeBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return maintenanceNoticeBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        View view;
        if (convertView == null) {
            view = inflater.inflate(R.layout.item_remesnotice, null);
        } else {
            view = convertView;
        }
        TextView textView_notice_type = (TextView) view.findViewById(R.id.textView_notice_type);
        TextView textView_notice_title = (TextView) view.findViewById(R.id.textView_notice_title);
        TextView textView_notice_index = (TextView) view.findViewById(R.id.textView_notice_index);
        TextView textView_notice_persion = (TextView) view.findViewById(R.id.textView_notice_persion);

        textView_notice_type.setText(maintenanceNoticeBeanList.get(position).getNotice_type());
        textView_notice_title.setText(maintenanceNoticeBeanList.get(position).getNotice_title());
        textView_notice_index.setText(maintenanceNoticeBeanList.get(position).getNotice_index());
        textView_notice_persion.setText(maintenanceNoticeBeanList.get(position).getNotice_persion());

        RippleView remesNoticeRippleView = (RippleView) view.findViewById(R.id.remesNoticeRippleView);
        remesNoticeRippleView.setRippleDuration(100);
        remesNoticeRippleView.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                Intent intent = new Intent(context, RemesNoticeDetailActivity.class);
                intent.putExtra("MaintenanceNoticeBean",maintenanceNoticeBeanList.get(position));
                context.startActivity(intent);
            }
        });

        return view;
    }
}
